<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments::head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客发布</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css">
    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css"/>
</head>
<body>
<!-- 导航 -->
<nav th:replace="admin/_fragments::menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">管理后台</h2>
            <a href="#" class="active m-item item m-mobile-hide"><i class="home icon"></i> 博客</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="idea icon"></i> 分类</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="tags icon"></i> 标签</a>
            <!-- 头像 -->
            <div class="m-item m-mobile-hide right menu">
                <div class="ui dropdown item">
                    <div class="text">
                        <img src="https://picsum.photos/id/1033/100/100" alt="" class="ui avatar image">
                        苏俊廷
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui black icon button m-right-top m-mobile-show menu toggle">
        <i class="sidebar icon"></i>
    </a>
</nav>
<!-- 二级导航 -->
<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a href="#" th:href="@{/admin/blogs/input}" class="active teal item">发布</a>
            <a href="#" th:href="@{/admin/blogs}" class="item">列表</a>
        </div>
    </div>
</div>

<!-- 中间内容 -->
<div class="m-padded-tb-large m-container-small">
    <div class="ui container">
        <form id="blog-form" action="#" th:object="${blog}" th:action="@{/admin/blogs}" method="post" class="ui form">
            <!--是否已发布 0 未发布 1 已发布-->
            <input type="hidden" name="published">
            <input type="hidden" name="id" th:value="*{id}">
            <div class="required field">
                <div class="ui left labeled input">
                    <div class="ui selection compact teal basic dropdown label">
                        <input type="hidden" name="flag" value="原创" th:value="*{flag}==null?'原创':*{flag}">
                        <i class="dropdown icon"></i>
                        <div class="text">原创</div>
                        <div class="menu">
                            <div class="item" data-value="原创">原创</div>
                            <div class="item" data-value="转载">转载</div>
                            <div class="item" data-value="翻译">翻译</div>
                        </div>
                    </div>
                    <input type="text" name="title" th:value="*{title}" placeholder="标题">
                </div>
            </div>

            <div class="field">
                <textarea name="description" th:text="*{description}" rows="5" placeholder="博客描述"></textarea>
            </div>

            <div class="field">
                <div id="md-content" style="z-index: 1">
                        <textarea name="content" placeholder="博客内容" style="display:none;" th:text="*{content}">
[TOC]

#### Disabled options

- TeX (Based on KaTeX);
- Emoji;
- Task lists;
- HTML tags decode;
- Flowchart and Sequence Diagram;

#### Editor.md directory

    editor.md/
            lib/
            css/
            scss/
            tests/
            fonts/
            images/
            plugins/
            examples/
            languages/
            editormd.js
            ...

```html
<!-- English -->
<script src="../dist/js/languages/en.js"></script>

<!-- 繁體中文 -->
<script src="../dist/js/languages/zh-tw.js"></script>
```
                        </textarea>
                </div>

            </div>

            <div class="two fields">
                <div class="field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">分类</label>
                        <div class="ui fluid selection dropdown">
                            <input type="hidden" name="type.id" th:value="*{type}!=null ? *{type.id}">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div class="item" th:each="type: ${types}" data-value="1" th:data-value="${type.id}" th:text="${type.name}">错误日志</div>
                                <!--/*-->
                                <div class="item" data-value="2">开发者手册</div>
                                <!--*/-->
                            </div>
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">标签</label>
                        <div class="ui fluid multiple search selection dropdown">
                            <input type="hidden" name="tagIds" th:value="*{tagIds}">
                            <i class="dropdown icon"></i>
                            <div class="default text">标签</div>
                            <div class="menu">
                                <div class="item" th:each="tag: ${tags}" data-value="1" th:data-value="${tag.id}" th:text="${tag.name}">JAVA</div>
                                <!--/*-->
                                <div class="item" data-value="2">Python</div>
                                <!--*/-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="field">
                <div class="ui left labeled input">
                    <label class="ui teal basic label">首图</label>
                    <input type="text" name="firstPicture" th:value="*{firstPicture}" placeholder="首图引用地址">
                </div>
            </div>

            <div class="inline fields">
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend" th:checked="*{id}==null?true:*{recommend}" class="hidden" checked>
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="appreciation" name="appreciation" th:checked="*{id}==null?true:*{appreciation}" class="hidden">
                        <label for="appreciation">赞赏</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="shareStatement" name="shareStatement" th:checked="*{shareStatement}" class="hidden">
                        <label for="shareStatement">转载声明</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="commentabled" name="commentabled" th:checked="*{commentabled}" class="hidden">
                        <label for="commentabled">评论</label>
                    </div>
                </div>
            </div>

            <div class="ui error message"></div>

            <div class="ui right aligned container">
                <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                <button type="button" id="save-btn" class="ui secondary button">保存</button>
                <button type="button" id="publish-btn" class="ui teal button">发布</button>
            </div>

        </form>


    </div>
</div>

<!--  底部 footer  -->
<footer th:replace="admin/_fragments::footer" class="ui inverted segment vertical m-padded-tb-massive">
    <div class="ui center aligned container">
        <div class="ui inverted divided grid stackable">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../../static/images/wechat.png" class="ui rounded image" style="width: 125px;">
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <div class="ui inverted link list">
                    <h4 class="ui inverted header m-opacity-mini">最新博客</h4>
                    <a href="#" class="item">用户故事（user story）</a>
                    <a href="#" class="item">用户故事（user story）</a>
                    <a href="#" class="item">用户故事（user story）</a>
                    <a href="#" class="item">用户故事（user story）</a>
                </div>
            </div>
            <div class="three wide column">
                <div class="ui inverted link list">
                    <h4 class="ui inverted header m-opacity-mini">联系我</h4>
                    <a href="#" class="item">Email：1358842247@qq.com</a>
                    <a href="#" class="item">QQ：1358842247</a>
                </div>
            </div>
            <div class="seven wide column">
                <div class="ui inverted link list m-opacity-mini">
                    <h4 class="ui inverted header ">博客介绍</h4>
                    <p>这是我的个人博客。。。。。。。。。。。。。。。。。。</p>
                </div>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-spaced m-opacity-tiny">Copyright @ 2020-2021 Lirenmi Designed by Lirenmi</p>
    </div>
</footer>

<th:block th:replace="admin/_fragments::script">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
    <script src="../../static/lib/editormd/editormd.min.js"></script>
</th:block>

<script>


    // 初始化Markdown编辑器
    var contentEditor;
    $(function () {
        contentEditor = editormd("md-content", {
            width: "100%",
            height: 640,
            syncScrolling: "single",
            // path: "../../static/lib/editormd/lib/"
            path: "/lib/editormd/lib/",

            //开启图片上传
            imageUpload : true,
            //图片上传支持的格式
            imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
            //图片上传的路径
            imageUploadURL : "/admin/oss/upload"
            // saveHTMLToTextarea : true

        });
    });


    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    // $('.ui.search.selection.dropdown')
    //     .dropdown({
    //         allowAdditions: true
    //     })
    // ;

    $('#save-btn').click(function () {
        $('[name="published"]').val(false);
        $('#blog-form').submit();
    });

    $('#publish-btn').click(function () {
        $('[name="published"]').val(true);
        $('#blog-form').submit();
    });

    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'title',
                rules: [{
                    type: 'empty',
                    prompt: '标题错误：博客标题不能为空！'
                }]
            },
            description: {
                identifier: 'description',
                rules: [{
                    type: 'empty',
                    prompt: '需要描述：博客描述不能为空！'
                }]
            },
            content: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '内容错误：博客内容不能为空！'
                }]
            },
            typeId: {
                identifier: 'type.id',
                rules: [{
                    type: 'empty',
                    prompt: '分类错误：博客分类不能为空！'
                }]
            }
        }
    });
</script>
<script th:replace="admin/_fragments::footerScript"></script>
</body>
</html>